# @author: jungle
# @create : 2024/10/14 22:40

"""
动态加载ui文件
"""

import sys
import time

from PyQt5 import uic
from PyQt5.QtWidgets import *


class MyWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.ui = None
        self.init_ui()

    def init_ui(self):
        self.ui = uic.loadUi("./ui/login.ui")
        # print(self.ui) # 谁?.ui文件中最顶层的对象(Form)
        # print(self.ui.__dict__) # 谁?最顶层对象的所有属性(key:value方式显示)
        # print(self.ui.label) # 谁?最顶层对象中嵌套的QLabls
        # print(self.ui.label.text()) # 谁?最顶层对象中嵌套的QLable的文本

        self.text_input = self.ui.lineEdit  # 用户名输入框
        self.password_input = self.ui.lineEdit_2  # 密码输入框
        login_btn = self.ui.pushButton  # 登录按钮
        self.forget_btn = self.ui.pushButton_2  # 忘记密码按钮
        self.text_browser = self.ui.textBrowser  # 文本显示区域

        # 给登录按钮被点击绑定槽函数
        login_btn.clicked.connect(self.my_login)

    def my_login(self):
        """
        实现登录的逻辑
        :return:
        """
        print("正在登录。。。。。。")
        # 提取用户名， 密码
        user_name = self.text_input.text()
        password = self.password_input.text()

        for i in range(10):
            print("正在登录服务器。。。。%d" % (i + 1))
            time.sleep(1)


        if user_name == "admin" and password == "123456":
            self.text_browser.setText("欢迎%s" % user_name)
            self.text_browser.repaint()
        else:
            self.text_browser.setText("用户名或者密码错误。。。。请重试")
            self.text_browser.repaint()


if __name__ == '__main__':
    app = QApplication(sys.argv)

    w = MyWindow()
    # 展示窗口
    w.ui.show()

    app.exec()
